const _ = require('lodash')
;

const options = {
  timestamp: Date.parse(new Date()),
};

module.exports = function setup(server) {
  const router = server.loopback.Router();

  router.get('/', (req, res) => res.redirect('/api/apps/login'));
  router.get('/request', (req, res) => res.redirect('/request/home'));
  // 历史遗留问题，以后迭代代码可删除这个跳转
  router.get('/request/detail', (req, res) => {
    let url = `/request/eContractDetail?model=${req.query.model}&formId=${req.query.formId}`;
    if (!_.isEmpty(req.query.id)) {
      url += `&id=${req.query.id}`;
    }
    if (!_.isEmpty(req.query.form)) {
      url += '&backId=3';
    }
    res.redirect(url);
  });

  router.get('/request/home', (req, res) => res.render('e-lanco/index', options));
  router.get('/request/selectType', (req, res) => res.render('e-lanco/select-type', options));
  router.get('/request/submitList', (req, res) => res.render('e-lanco/submit-list', options));
  router.get('/request/approvalList', (req, res) => res.render('e-lanco/approval-list', options));
  router.get('/request/exportList', (req, res) => res.render('e-lanco/export-list', options));
  router.get('/request/approvalflow', (req, res) => res.render('e-lanco/approval-flow', options));
  router.get('/request/eContractDetail', (req, res) => res.render('e-lanco/e-contract-detail', options));
  router.get('/request/manpowerRequisitionDetail', (req, res) => res.render('e-lanco/manpower-requisition-detail', options));
  router.get('/request/sourcingRequisitionDetail', (req, res) => res.render('e-lanco/sourcing-requisition-detail', options));

  router.get('/admin/dictionaryList', (req, res) => res.render('admin/dictionary-list', options));
  router.get('/admin/userList', (req, res) => res.render('admin/user-list', options));
  router.get('/admin/roleList', (req, res) => res.render('admin/role-list', options));
  router.get('/admin/templateList', (req, res) => res.render('admin/template-list', options));

  server.use(router);
};
